
package PengendaliSuratDokumen;

import java.sql.Connection;
import java.sql.SQLException;
import oracle.jdbc.pool.OracleDataSource;

public class KoneksiOracle {
//    String jdbcUrl  = "jdbc:oracle:thin:@172.23.9.185:1521:orcl"; // Database kampus
//    String jdbcUrl  = "jdbc:oracle:thin:@localhost:1521:XE";
//    String userid   = "MHS115314093";
//    String password = "MHS115314093";
    
    
    String jdbcUrl  = "jdbc:oracle:thin:@localhost:1521:XE";
//    String userid   = "suratdokumen";
//    String password = "suratdokumen";
    String userid   = "hr";
    String password = "hr";
    
//    "oracle.jdbc.driver.OracleDriver"
    public Connection conn;
    
    public KoneksiOracle(){
    }
    
    public void getDBConnection() {
        try {
            OracleDataSource ds;
            ds = new OracleDataSource();
            ds.setURL(jdbcUrl);
            conn = ds.getConnection(userid, password);
            System.out.println("Koneksi berhasil ^o^");

        } catch (SQLException ex) {
            System.out.println("Koneksi gagal!");
        }
    }
    public void closeDBConnection() {
        try {
            conn.close();
        } catch (SQLException ex) {
            System.out.println("Koneksi tidak bisa ditutup!");
        }
    }
    public static void main(String[] args) {
        KoneksiOracle koneksiOracle = new KoneksiOracle();
        koneksiOracle.getDBConnection();
        koneksiOracle.closeDBConnection();
    }
}
